home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / apower1a / split.bas next >
Encoding:
BASIC Source File  |  1999-09-21  |  1.6 KB  |  49 lines

  1. Attribute VB_Name = "split_mod"
  2. '***************************************************************
  3. ' Name: My own Split function for Vb5
  4. '
  5. ' Description: It's my version of the 'Split' Vb 6
  6. '              function for Vb5 Users ...
  7. '
  8. ' By: JΘrΘmy cluzel
  9. '     jcluzel@hotmail.com
  10. '
  11. ' Inputs:   chaine: string to separate
  12. '           separ: string used as separator, may be more than
  13. '                  one charactere long. Ex: '|', ';', or 'XX'...
  14. '           tableau() : array of string used to store elements
  15. '                       after separation
  16. '           nb_elem : integer used to store the number
  17. '                     of elements (in the array above...)
  18. '
  19. ' Returns:  0, if everything works...
  20. '           the number of the error generated else ...
  21. '
  22. 'Assumes:None
  23. '
  24. 'Side Effects: If you want to use it under Vb6 rename it
  25. '              to 'split_' or whatever you want...
  26. '
  27. '***************************************************************
  28.  
  29. Option Explicit
  30. Public Function split(chaine As String, separ As String, tableau() As String, nb_elem As Integer) As Integer
  31.     On Error GoTo erreur
  32.     Dim pos_act As Integer, pos_occur As Integer
  33.     If Right(chaine, 1) <> separ Then chaine = chaine & separ
  34.     Do
  35.         pos_act = pos_occur + Len(separ)
  36.         pos_occur = InStr(pos_act, chaine, separ)
  37.         If pos_occur <> 0 Then
  38.             ReDim Preserve tableau(nb_elem)
  39.             tableau(nb_elem) = Mid(chaine, pos_act, pos_occur - pos_act)
  40.             nb_elem = nb_elem + 1
  41.         End If
  42.     Loop Until pos_occur = 0
  43.     split = 0
  44. Exit Function
  45.  
  46. erreur:
  47.     split = Err.Number
  48. End Function
  49.